import request from './index'
// 是否全局消息提示
const requestOptions = {
  globalErrorMessage: true,
  globalSuccessMessage: true
}
// 查询用户列表
export function getUserList(data?: any) {
  return request.get(`users?condition=${data.condition}&pageNum=${data.pageNum}&pageSize=${data.pageSize}`, {
    requestOptions
  })
}

// 创建用户
export function createUser(data?: any) {
  return request.post('users', data, {
    requestOptions
  })
}

// 修改用户
export function modifyUser(data?: any) {
  return request.put(
    `users/${data.id}`, // params参数
    {
      // body参数
      email: data.email,
      mobile: data.mobile
    },
    {
      requestOptions
    }
  )
}

// 删除用户
export function deleteUser(data?: any) {
  return request.delete(`users/${data.id}`, {
    requestOptions
  })
}

// 更改用户状态
export function modifyUserStatus(data?: any) {
  return request.put(`users/${data.id}/state/${data.state}`, null, {
    requestOptions
  })
}

// 分配用户角色
export function setUserRole(data?: any) {
  return request.put(
    `users/${data.id}/role`,
    { rid: data.rid },
    {
      requestOptions
    }
  )
}
